package com.gxa.meiye.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.gxa.meiye.admin.mapper.RefundMapper;
import com.gxa.meiye.admin.service.RefundService;
import com.gxa.meiye.core.common.ResponseData;
import com.gxa.meiye.core.pojo.domain.lzj.Refund;
import com.gxa.meiye.core.pojo.vo.RefundReasonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class RefundServiceImpl extends ServiceImpl<RefundMapper,RefundReasonVO> implements RefundService{


    @Autowired
    private RefundMapper refundMapper;
    @Override
    public ResponseData queryAll() {
        ResponseData rd=new ResponseData();
        List<RefundReasonVO> cs = refundMapper.queryAll();
        rd.setCode(200);
        rd.setMsg("查询成功");
        rd.setData(cs);
        return rd;
    }

    @Override
    public ResponseData addReFund(String image, String ordernumber, Refund refund) {

        ResponseData rd=new ResponseData();
        Integer a=10;
        BigDecimal bigDecimal = new BigDecimal(a);
        BigDecimal money = refundMapper.queryByOrderNumber(ordernumber);
        BigDecimal m1 = money.subtract(bigDecimal);
        refund.setReturnMoney(m1);
        refund.setRefundImage(image);
        Integer i = refundMapper.updaterefund(refund);
        if (i > 0) {
            rd.setCode(200);
            rd.setMsg("添加成功");
        } else {
            rd.setCode(500);
            rd.setMsg("添加失败");
        }
        return rd;
    }
}
